// Fill out your copyright notice in the Description page of Project Settings.


#include "Core/PaperZDAnimNotify_Attack.h"
#include "Kismet/KismetSystemLibrary.h"

#include "PaperZDAnimInstance.h"

void UPaperZDAnimNotify_Attack::OnReceiveNotify_Implementation(UPaperZDAnimInstance* OwningInstance) const
{
	if (OwningInstance)
	{
		GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, FString::Printf(TEXT("%s 发起攻击！"), *OwningInstance->GetName()));

		AActor* OwnerActor = OwningInstance->GetOwningActor();
		
		TArray<TEnumAsByte<EObjectTypeQuery>> QueryType;
		// QueryType.Emplace(EObjectTypeQuery::ObjectTypeQuery5);
		QueryType.Emplace(UEngineTypes::ConvertToObjectType(ECollisionChannel::ECC_GameTraceChannel1));
		
		TArray<AActor*> Ignore;
		Ignore.Emplace(OwnerActor);
		
		TArray<FHitResult> HitResults;
		
		const FVector Location = OwnerActor->GetActorLocation();
		UKismetSystemLibrary::SphereTraceMultiForObjects(GetWorld(), Location, Location, 100.0f, QueryType, false, Ignore, EDrawDebugTrace::ForDuration, HitResults, true);

		// 处理碰撞结果
		for (FHitResult Hit : HitResults)
		{
			AActor* HitActor = Hit.GetActor();
			if (HitActor)
			{
				// 在这里可以进行与碰撞到的Actor相关的操作，比如造成伤害等
				UE_LOG(LogTemp, Warning, TEXT("Hit Actor: %s"), *HitActor->GetName());
			}
		}

	}
}

FName UPaperZDAnimNotify_Attack::GetDisplayName_Implementation() const
{
	return FName("Attack");
}
